package priv.mill.server;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.apache.log4j.Logger;

public class SessionContext {
	private static final Logger logger = Logger.getLogger(SessionContext.class);
	private static Map<ChannelHandlerContext, ChinaUser> map=new HashMap<>();

	public static void remove(Channel channel) {
		map.remove(channel);
	}

	public static void put(ChannelHandlerContext ctx) {
		map.put(ctx, null);
	}

	public static void put(ChannelHandlerContext channel, ChinaUser msg) {
		ChinaUser chinaUser = map.get(channel);
		if(chinaUser==null){
			map.put(channel, msg);
		}
	}

	public static void Each(SerssionHandler serssionHandler) {
		
		Set<Entry<ChannelHandlerContext, ChinaUser>> entrySet = map.entrySet();
		Iterator<Entry<ChannelHandlerContext, ChinaUser>> iterator = entrySet.iterator();
		while (iterator.hasNext()) {
			Entry<ChannelHandlerContext, ChinaUser> next = iterator.next();
			
			serssionHandler.handlerSession(next.getKey(),next.getValue());
		}
		
	}
	
	
	
	
}
